package com.ita.activemq;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.ita.dto.ActivityDto;
import com.ita.service.TenderRecordService;
import com.ita.util.JacksonUtil;

public class QueueMessageListener implements MessageListener {

	// 当收到消息后，自动调用该方法
	@Autowired(required = true)
	private TenderRecordService trs;

	@Override
	public void onMessage(Message message) {

		TextMessage tm = (TextMessage) message;
		try {
			System.out.println("QueueMessageListener监听到了文本消息：\t" + tm.getText());
			// do something ...

			ActivityDto activityDto = JacksonUtil.getObjectFromJson(tm.getText(), ActivityDto.class);
			String activityId = activityDto.getActivity_id();
			String mid = activityDto.getM_id();
			int state = activityDto.getState();
			trs.update(activityId, mid, state);

		} catch (JMSException e) {
			e.printStackTrace();
		}
	}

}